/**
 * 功能描述 表单
 */

define(function (require, exports, module){
	var Form = require("form");
	var aw = require("ajaxwrapper");
	var store =require("store");
	var tools = require("tools");
	var Dialog = require("dialog");
	var activeUser = store.get("user");
	
	var instance = {
		initComponent: function (params,widget){
            var form = new Form({
				parentNode:".J-form",
				show:false,
				saveaction:function(){
        			var data = form.getData();
					aw.saveOrUpdate("api/goods/save",data,function(data){
						widget.get("grid").refresh();
						widget.show([".J-grid"]).hide([".J-form"]);
						widget.get("subnav").show(["add","search"]);//.hide(["return"])
					});
        			
        		},
        		cancelaction : function(){
           			     widget.show([".J-grid"]).hide([".J-form"]);
    					 widget.get("subnav").show(["add","search"]);//.hide(["return"])
    					 widget.get("grid").refresh();
        		},
				model:{
					id:"form",
//					layout: "2_1",
					items:[{
						name:"pkGoods",
						type:"hidden",
					},{
						name:"version",
						defaultValue:"0",
						type:"hidden"
					},{
						name:"organization",
						type:"hidden",
						defaultValue:activeUser.organization.pkOrganization
					},{
						name:"name",
						label:"名称",
						validate:["required"]
					},{
						name:"createDate",
						type:"hidden",
						defaultValue:moment().format("YYYY-MM-DD")
					},{
						name:"roomGoods",
						label:"产品消费品",
	        			type:"radio",
	        			list:[{
	        				key:"true",
	        				value:"是"
	        				},{
	        				key:"false",
	        				value:"否"
	        			}]
					},{
						name:"roomAssets",
						label:"房间资产",
						type:"radio",
	        			list:[{
	        				key:"true",
	        				value:"是"
	        				},{
	        				key:"false",
	        				value:"否"
	        			}]
					},{
						name:"description",
						label:"备注",
						type:"textarea"
					}]
				}
			});
			widget.set("form", form);
		}
	};
	module.exports = instance;
});